package com.sneaker.shower.config;

import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
import cn.binarywang.wx.miniapp.config.WxMaConfig;
import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


/**
 * @author Hechangjian
 * @version 1.0
 * @className WxMaConfiguraton
 * @date 2019/07/26 18:03
 * @description 微信小程序Sdk初始化
 * @program bath
 */
@Configuration
@EnableConfigurationProperties(WxMaProperties.class)
public class WxMaConfiguration {
    private static WxMaService wxMaService;

    private WxMaProperties wxMaProperties;

    @Autowired
    public WxMaConfiguration(WxMaProperties wxMaProperties) {
        this.wxMaProperties = wxMaProperties;
    }

    @Bean
    public WxMaConfig wxMaConfig() {
        WxMaDefaultConfigImpl wxMaDefaultConfig = new WxMaDefaultConfigImpl();
        wxMaDefaultConfig.setAppid(wxMaProperties.getAppId());
        wxMaDefaultConfig.setSecret(wxMaProperties.getAppSecret());
        wxMaDefaultConfig.setToken(wxMaProperties.getToken());
        wxMaDefaultConfig.setAesKey(wxMaProperties.getAESKey());
        wxMaDefaultConfig.setMsgDataFormat(wxMaProperties.getMsgDataFormat());
        return wxMaDefaultConfig;
    }

    @Bean
    public WxMaService wxMaService() {
        wxMaService = new WxMaServiceImpl();
        wxMaService.setWxMaConfig(wxMaConfig());
        return wxMaService;
    }

}
